# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=xavs
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.1.55
pkgrel=1
pkgdesc="XAVS is to implement high quality encoder and decoder of the Audio Video Standard of China (AVS). (mingw-w64)"
arch=('any')
url="https://xavs.sourceforge.io/"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "${MINGW_PACKAGE_PREFIX}-yasm")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
source=("https://github.com/OpenMandrivaAssociation/xavs/raw/master/xavs-${pkgver}.tar.xz"
        "0001-xavs-0.1.55-fix-dynamic-build.patch"
        "0002-xavs-0.1.55-fix-asm.patch")
sha256sums=("178bf04ffc5edd9acfa8188acbeeab16e24e4e43f4465729e8619f844e5901f2"
            "0a6bdb653db4c63ab1c60ee5fd7303215523e6e06f62998c7a06520798be92c4"
            "1559e0dfb21ee6f67dbd996ae0bb0c67987706db3144199202890de37cb7d8b4")

prepare(){
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/0001-xavs-0.1.55-fix-dynamic-build.patch"
  patch -Np1 -i "${srcdir}/0002-xavs-0.1.55-fix-asm.patch"
  sed -i -e 's|$(CC) -o $@ $(OBJCLI) $(LDFLAGS) -L. -lxavs|$(CC) -o $@ $(OBJCLI) -L. -lxavs $(LDFLAGS)|' Makefile
  sed -i -e 's|xavs$(EXE): $(OBJCLI) $(SONAME)|xavs$(EXE): $(OBJCLI) $(SONAME) libxavs.a|' Makefile
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MINGW_CHOST}/${_realname}-${pkgver}"
  cd "${_realname}-${pkgver}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --disable-asm \
    --enable-shared

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}/${_realname}-${pkgver}"
  make DESTDIR=${pkgdir} install
}
